package com.techstar.ats.netty;

import io.netty.buffer.ByteBuf;
import com.techstar.ats.MessageType;
import com.techstar.ats.codec.Codec;

public enum ASDUCodec implements Codec<ASDU> {
	INSTANCE;

	public static final int LEN = 10;

	public ASDU create() {
		return new ASDU();
	}

	public void encode(ByteBuf buf, ASDU value) {
		buf.writeShort(value.len);
		buf.writeInt(value.time);
		buf.writeShort(value.version);
		buf.writeShort(value.type.ordinal());
	}

	public void decode(ByteBuf buf, ASDU value) {
		value.len = buf.readUnsignedShort();
		value.time = buf.readInt();
		value.version = buf.readUnsignedShort();
		value.type = MessageType.valueOf(buf.readUnsignedShort());
	}
}
